package MapBase.logic.control.Entity
{
	import com.utils.keymanager.Key;
	
	import flash.display.Sprite;

	public class EntityDepthDot
	{
		private var _entity:Sprite;
		
		private var _dotSprite : Sprite;
		
		public var _x:Number;
		public var _y:Number;
		public var _r:Number;
		
		public var step : int;
		
		public function EntityDepthDot(entity:Sprite,x:Number=10,y:Number=10,r:Number=5)
		{
			_entity= entity;
			_dotSprite = new Sprite;
			step =1;
			
			this._x = x;
			this._y = y;
			this._r = r;
			
			_entity.addChild(_dotSprite);
			setLineStyle();
			
			draw();
		}
		
		public function invalidateDraw():void
		{
			draw();
		}
		
		public function keyControl(keyCode:int):void
		{
			switch(keyCode)
			{
				case Key.UP:
					_dotSprite.y-=step;
					break;
				case Key.DOWN:
					_dotSprite.y+=step;
					break;
				case Key.LEFT:
					_dotSprite.x-=1;
					break;
				case Key.RIGHT:
					_dotSprite.x+=1;
					break;
			}
		}
		
		public function startDrag():void
		{
			_dotSprite.startDrag();
		}
		
		public function stopDrag():void
		{
			_dotSprite.stopDrag();
		}
		
		public function invalidate():void
		{
			draw();
		}
		
		public function clear():void
		{
			_dotSprite.graphics.clear();
			
			_entity.removeChild(_dotSprite);
		}
		
		public function setLineStyle(thickness:int=1,color:uint=0x000000) : void
		{
			_dotSprite.graphics.lineStyle(thickness,color);
		}
		
		private function draw():void
		{
			_dotSprite.graphics.beginFill(0xffff00);
			_dotSprite.graphics.drawCircle(_x,_y,_r);
			_dotSprite.graphics.endFill();
		}
	}
}